package com.lzh.chatnote.chat.controller;


import com.lzh.chatnote.chat.domain.vo.request.message.MessagePageReq;
import com.lzh.chatnote.chat.domain.vo.request.message.MessageSendReq;
import com.lzh.chatnote.chat.domain.vo.response.message.MessageResp;
import com.lzh.chatnote.chat.service.MessageService;
import com.lzh.chatnote.common.domain.response.ApiResult;
import com.lzh.chatnote.common.domian.vo.response.CursorPageBaseResp;
import com.lzh.chatnote.common.utils.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 消息表 前端控制器
 * </p>
 *
 * @author lzh
 * @since 2025-09-25
 */

@Api(tags = "消息接口控制器")
@RestController
@RequestMapping("/api/message")
public class MessageController {

    @Resource
    private MessageService messageService;

    /**
     * 聊天消息游标分页列表
     */
    @ApiOperation("聊天消息游标分页列表")
    @GetMapping("/queryCursorPage")
    public ApiResult<CursorPageBaseResp<MessageResp>> queryCursorPage(@Valid MessagePageReq messagePageReq){
        return ApiResult.success(messageService.queryCursorPage(messagePageReq));
    }

    /**
     * 发送消息
     */
    @ApiOperation("发送消息")
    @PostMapping("/sendMsg")
    public ApiResult<MessageResp> sendMsg(@RequestBody @Valid MessageSendReq messageSendReq){
        Long msgId  = messageService.sendMsg(messageSendReq,UserUtils.getCurrentUserId());
        return ApiResult.success(messageService.buildSendMsgResp(msgId,UserUtils.getCurrentUserId()));
    }

}

